package com.sihai.core;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

/**
 * <code>LimitedList</code> 数据库部分结果集对象,封装了查询结果的列表和总记录数,应用程序可以使用该类表示查询结果
 */
public class LimitedList<E> implements List<E>, Serializable {

	private static final long serialVersionUID = 7595430732290001936L;

	private int totalcount;/* 总记录数 */

	/**
	 * @return 总记录数
	 */
	public int getTotalcount() {
		return totalcount;
	}

	/**
	 * @param totalcount 总记录数
	 */
	public void setTotalcount(int totalcount) {
		this.totalcount = totalcount;
	}

	/**
	 * create LimitedList with totalcount and delegate list
	 * 
	 * @param totalcount total count
	 * @param delegate delegate list
	 */
	public LimitedList(int totalcount, List<E> delegate) {
		this.totalcount = totalcount;
		this.delegate = delegate;
	}

	public LimitedList(int totalcount) {
		this(totalcount, new ArrayList<E>());
	}

	/**
	 * create {@link com.sihai.core.LimitedList} with delegate list and totalcount = delegate.size()
	 * 
	 * @param delegate delegate list
	 */
	public LimitedList(List<E> delegate) {
		this(delegate == null ? 0 : delegate.size(), delegate);
	}

	public LimitedList() {
		this(new ArrayList<E>());
	}

	private List<E> delegate;

	public boolean add(E e) {
		return delegate.add(e);
	}

	public void add(int index, E element) {
		delegate.add(index, element);
	}

	public boolean addAll(Collection<? extends E> c) {
		return delegate.addAll(c);
	}

	public boolean addAll(int index, Collection<? extends E> c) {
		return delegate.addAll(index, c);
	}

	public void clear() {
		delegate.clear();
	}

	public boolean contains(Object o) {
		return delegate.contains(o);
	}

	public boolean containsAll(Collection<?> c) {
		return delegate.containsAll(c);
	}

	@Override
	public boolean equals(Object o) {
		return delegate.equals(o);
	}

	public E get(int index) {
		return delegate.get(index);
	}

	@Override
	public int hashCode() {
		return delegate.hashCode();
	}

	public int indexOf(Object o) {
		return delegate.indexOf(o);
	}

	public boolean isEmpty() {
		return delegate.isEmpty();
	}

	public Iterator<E> iterator() {
		return delegate.iterator();
	}

	public int lastIndexOf(Object o) {
		return delegate.lastIndexOf(o);
	}

	public ListIterator<E> listIterator() {
		return delegate.listIterator();
	}

	public ListIterator<E> listIterator(int index) {
		return delegate.listIterator(index);
	}

	public E remove(int index) {
		return delegate.remove(index);
	}

	public boolean remove(Object o) {
		return delegate.remove(o);
	}

	public boolean removeAll(Collection<?> c) {
		return delegate.removeAll(c);
	}

	public boolean retainAll(Collection<?> c) {
		return delegate.retainAll(c);
	}

	public E set(int index, E element) {
		return delegate.set(index, element);
	}

	public int size() {
		return delegate.size();
	}

	public List<E> subList(int fromIndex, int toIndex) {
		return delegate.subList(fromIndex, toIndex);
	}

	public Object[] toArray() {
		return delegate.toArray();
	}

	public <T> T[] toArray(T[] a) {
		return delegate.toArray(a);
	}

	@Override
	public String toString() {
		return delegate.toString();
	}
}
